package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlQuestionAttempts entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlQuestionAttempts
 * @author MyEclipse Persistence Tools
 */

public class MdlQuestionAttemptsDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlQuestionAttemptsDAO.class);
	// property constants
	public static final String QUESTIONUSAGEID = "questionusageid";
	public static final String SLOT = "slot";
	public static final String BEHAVIOUR = "behaviour";
	public static final String QUESTIONID = "questionid";
	public static final String VARIANT = "variant";
	public static final String MAXMARK = "maxmark";
	public static final String MINFRACTION = "minfraction";
	public static final String FLAGGED = "flagged";
	public static final String QUESTIONSUMMARY = "questionsummary";
	public static final String RIGHTANSWER = "rightanswer";
	public static final String RESPONSESUMMARY = "responsesummary";
	public static final String TIMEMODIFIED = "timemodified";

	public void save(MdlQuestionAttempts transientInstance) {
		log.debug("saving MdlQuestionAttempts instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlQuestionAttempts persistentInstance) {
		log.debug("deleting MdlQuestionAttempts instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlQuestionAttempts findById(java.lang.Long id) {
		log.debug("getting MdlQuestionAttempts instance with id: " + id);
		try {
			MdlQuestionAttempts instance = (MdlQuestionAttempts) getSession()
					.get("idv.loveloser.dao.MdlQuestionAttempts", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlQuestionAttempts instance) {
		log.debug("finding MdlQuestionAttempts instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlQuestionAttempts")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlQuestionAttempts instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlQuestionAttempts as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByQuestionusageid(Object questionusageid) {
		return findByProperty(QUESTIONUSAGEID, questionusageid);
	}

	public List findBySlot(Object slot) {
		return findByProperty(SLOT, slot);
	}

	public List findByBehaviour(Object behaviour) {
		return findByProperty(BEHAVIOUR, behaviour);
	}

	public List findByQuestionid(Object questionid) {
		return findByProperty(QUESTIONID, questionid);
	}

	public List findByVariant(Object variant) {
		return findByProperty(VARIANT, variant);
	}

	public List findByMaxmark(Object maxmark) {
		return findByProperty(MAXMARK, maxmark);
	}

	public List findByMinfraction(Object minfraction) {
		return findByProperty(MINFRACTION, minfraction);
	}

	public List findByFlagged(Object flagged) {
		return findByProperty(FLAGGED, flagged);
	}

	public List findByQuestionsummary(Object questionsummary) {
		return findByProperty(QUESTIONSUMMARY, questionsummary);
	}

	public List findByRightanswer(Object rightanswer) {
		return findByProperty(RIGHTANSWER, rightanswer);
	}

	public List findByResponsesummary(Object responsesummary) {
		return findByProperty(RESPONSESUMMARY, responsesummary);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findAll() {
		log.debug("finding all MdlQuestionAttempts instances");
		try {
			String queryString = "from MdlQuestionAttempts";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlQuestionAttempts merge(MdlQuestionAttempts detachedInstance) {
		log.debug("merging MdlQuestionAttempts instance");
		try {
			MdlQuestionAttempts result = (MdlQuestionAttempts) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlQuestionAttempts instance) {
		log.debug("attaching dirty MdlQuestionAttempts instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlQuestionAttempts instance) {
		log.debug("attaching clean MdlQuestionAttempts instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}